package miracom.one.MilkProduction.util;

import milkproduction.dao.ProductionProcessDAO;
import milkproduction.service.ProductionProcessService;

public class Sterilizer extends Thread {
	private int rowMilkNo;//원유 정보 조회용
	private int rowMilkThroughput;//처리할 원유량
	private ProductionProcessDAO dao;
	
	public Sterilizer(int rowMilkNo,int rowMilkThroughput,ProductionProcessDAO dao){
		this.rowMilkNo = rowMilkNo;
		this.rowMilkThroughput = rowMilkThroughput;
		this.dao=dao;
	}

	@Override
	public void run() {
		try {
			ProductionProcessService.sterilizerProgressAmount = 0;//현재 작업량 0으로 초기화
			int cnt = rowMilkThroughput/10; //10L 당 살균 처리 시간 조정
			for(int i = 0 ; i<cnt;i++){
			this.sleep(100);//1초동안 처리
			ProductionProcessService.sterilizerProgressAmount = ProductionProcessService.sterilizerProgressAmount +10;//살균한 원류량
			System.out.println("살균기 : "+i);
			}
			System.out.println(rowMilkThroughput);
			int milkNo = dao.selectMilkSqe();
			dao.insertMilk(milkNo,rowMilkNo,rowMilkThroughput);//살균 완료 된 우유 우유 저장 창고로 이동
			ProductionProcessService.nowWorkAmoune = ProductionProcessService.nowWorkAmoune+rowMilkThroughput;//작업 완료량 update
			ProductionProcessService.sterilizerCnt = ProductionProcessService.sterilizerCnt+1;
			ProductionProcessService.sterilizerWork = false;//살균 작업 완료 표시
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
